'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:AdministratorAdminJyzCtrl
 * @description
 * # AdministratorAdminJyzCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('AdministratorAdminJyzCtrl', function($scope, openApi, $http, $filter, Util, $location, $routeParams, FormSubmit) {
        //获取证件信息列表
        $scope.getChoosecertId = function() {
            Util.saveSelectLists($scope.param.detailList);
            Util.savaParamForReview($scope.param, $routeParams.id);
            $location.path("administrator/chooseinfo/jyz");
        };
        // 删除证件信息列表
        $scope.deletedItem = function(index) {
            $scope.param.detailList.splice(index, 1);
            Util.saveSelectLists($scope.param.detailList);
        };
        var getAllpkIds = function() {
            var pkIds = [],
                pkIdsStr;
            $scope.param.detailList.forEach(function(item, index) {
                pkIds.push(item.pkId);
            });
            pkIdsStr = pkIds.join(",");
            return pkIdsStr;
        }

        $scope.submit = function() {
            // 底部类型end
            // 获取证件信息列表id
            $scope.param.sealIds = getAllpkIds();
            if (!$scope.param.returnDate) {
                Util.Toast("请选择预计归还日期");
                return;
            }
            if ($scope.param.detailList.length < 1) {
                Util.Toast("请选择证件信息");
                return;
            }

            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.borrowSeal
            var options = {};
            options.urlParam = urlParam;
            var myDest = {};
            options.param = angular.copy($scope.param, myDest);
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            delete options.param.detailList
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.borrowSeal
            }
            new FormSubmit(options);
        };
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
                // 获取选择页面返回的数据并且合并到参数中
                var selectLists;
                selectLists = Util.getSelectLists();
                $scope.param.detailList = selectLists || $scope.param.detailList || [];
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });
        };
        // 初始化
        init();

    });
